<?php

namespace App\Http\Controllers\Admin;

use App\Exports\EquipmentCompanyExport;
use App\Http\Filters\EquipmentCompanyFilter;
use App\Models\EquipmentCompany;
use App\Http\Requests\EquipmentCompanyRequest;
use App\Http\Resources\EquipmentCompanyResource;
use Illuminate\Http\Request;
use Maatwebsite\Excel\Facades\Excel;

class EquipmentCompanyController extends Controller
{
    public function index(EquipmentCompanyFilter $filter)
    {
        $equipmentCompanys = EquipmentCompany::query()
            ->filter($filter)
            ->paginate();

        return $this->ok(EquipmentCompanyResource::collection($equipmentCompanys));
    }

    public function create()
    {
        return $this->ok();
    }

    public function store(EquipmentCompanyRequest $request)
    {
        $inputs = $request->validated();
        $equipmentCompany = EquipmentCompany::create($inputs);

        return $this->created(EquipmentCompanyResource::make($equipmentCompany));
    }

    public function edit(Request $request, EquipmentCompany $equipmentCompany)
    {
        return $this->ok(EquipmentCompanyResource::make($equipmentCompany));
    }

    public function update(EquipmentCompanyRequest $request, EquipmentCompany $equipmentCompany)
    {
        $inputs = $request->validated();
        $equipmentCompany->update($inputs);

        return $this->created(EquipmentCompanyResource::make($equipmentCompany));
    }

    public function destroy(EquipmentCompany $equipmentCompany)
    {
        $equipmentCompany->delete();
        return $this->noContent();
    }
    public function export(Request $request)
    {

        $filters = $request->only([
            'ids',
            // ... 其他可能的过滤条件
        ]);
        return Excel::download(new EquipmentCompanyExport($filters), '厂家.xlsx');
    }
}
